﻿using ConfExpert.Forms.Base;
using ConfExpert.Forms.Depo;
using ConfExpert.Properties;

using DevTeam;

using System;
using System.Data;

namespace ConfExpert.Forms.Rapor.YeniYapi
{
    public partial class _POEtiketler : XForm
    {
        public _POEtiketler()
        {
            InitializeComponent();
        }

        private void POEtiketler_Load(object sender, EventArgs e)
        {
            ShowOnlyFooter();
            bool YetkiEditArsivMt = ytk(85);
            gvPOLines.Init("GetPOLinesforSticker");

            gvPOLines.MakeColumnInvisible("POLinesId");
            gvPOLines.SetCaptions("Sec:Seç", "KompozisyonId:Kompozisyon", "Agirlik:Ağırlık");

            if (YetkiEditArsivMt)
            {
                GridManager gmArt = GridManager.GetManager(gvPOLines);
                gmArt.GridMenu.AddMenu("Seç", SatirSec, Resources.Plus_16x16, true);
                gmArt.GridMenu.AddMenu("Bırak", SatirBirak, Resources.Minus_16x16);
                gmArt.GridMenu.AddMenu("Arşiv etiketi bas", PrintArsivEtiket, null);
                gmArt.GridMenu.AddMenu("Kalite etiketi bas", PrintKaliteEtiket, null);
            }

            gvPOLines.AddSummary();
            gvPOLines.BestFitColumns();
        }

        private void PrintKaliteEtiket(object sender, EventArgs e)
        {
            string POLinesIds = GetPOLinesIds();
            using (ArsivEtiketi ne = new ArsivEtiketi(POLinesIds, 2, "GetKaliteEtiketiPO"))
                ne.ShowDialog();
        }

        private string GetPOLinesIds()
        {
            gvPOLines.EndEditing();
            string POLinesIds = "";
            foreach (DataRow dr in gvPOLines.DataTable().Select("Sec=1"))
                POLinesIds += dr["POLinesId"].ToString() + ",";

            POLinesIds = POLinesIds.RemoveIfEndsWith(",");
            return POLinesIds;
        }

        private void PrintArsivEtiket(object sender, EventArgs e)
        {
            string POLinesIds = GetPOLinesIds();
            using (ArsivEtiketi ne = new ArsivEtiketi(POLinesIds, 1, "GetArsivEtiketiPO"))
                ne.ShowDialog();
        }

        private void SatirBirak(object sender, EventArgs e)
        {
            foreach (int handle in gvPOLines.GetSelectedRows())
                gvPOLines.SetRowCellValue(handle, "Sec", false);
        }

        private void SatirSec(object sender, EventArgs e)
        {
            foreach (int handle in gvPOLines.GetSelectedRows())
                gvPOLines.SetRowCellValue(handle, "Sec", true);
        }
    }
}
